sInput1 = input()
sInput2 = input()
i_num = int(sInput1.split()[0])
i_move = int(sInput1.split()[-1])
lst = sInput2.split()
lst_rtn = []
for i in range(i_num):
print(i,lst[i],(i+i_move)%i_num)
lst_rtn[(i+i_move)%i_num] = lst[i]
print(lst)
print(lst_rtn)
執行
6 2 #Input
1 2 3 4 5 6 #Input
Traceback (most recent call last):
File "D:move.py", line 8, in <module>
lst_rtn[(i+i_move)%i_num] = lst[i]
IndexError: list assignment index out of range
sInput1 = input()
sInput2 = input()
i_num = int(sInput1.split()[0])
i_move = int(sInput1.split()[-1])
lst = sInput2.split()
lst_rtn = []
str = ''
#iIndex = i_num - i_move + (i_num * int(i_move/i_num))
iIndex = i_num * (int(i_move/i_num) + 1) - i_move
for i in range(i_num):
#lst_rtn.append(lst[iIndex % i_num])
str += lst[iIndex % i_num] + ' '
iIndex +=1
print(str.rstrip())
#print(lst)
#print(lst_rtn)
本文純自己做題目之筆記,如有更好的方法再麻煩各位指教~~